
import {createRouter as _createRouter, createWebHistory} from 'vue-router';
import register from '../views/register.vue'
import login from "../views/login.vue";
import index from "../views/index/index.vue";
import city from "../views/index/city.vue";
import App from "../App.vue";
import {useStore} from "../pinia/index.js";
import houseInfo from "../views/index/houseInfo.vue";
import more from "../views/index/more.vue";
import contractInfo from "../views/index/contractInfo.vue";
import search from "../views/index/search.vue";
import businessTripRental from "../views/index/businessTripRental.vue";
import enterpriseDiscounts from "../views/index/enterpriseDiscounts.vue";
import graduationSeason from "../views/index/graduationSeason.vue";
import nearbyStores from "../views/index/nearbyStores.vue";
import ba1 from "../views/index/banner/ba1.vue";
import ba2 from "../views/index/banner/ba2.vue";
import ba3 from "../views/index/banner/ba3.vue";
import ba4 from "../views/index/banner/ba4.vue";
import my from "../views/my/index.vue";
import activity from "../views/my/activity.vue"
import message from "../views/my/message.vue"
import userDetail from "../views/user/userDetail.vue";
import userNickname from "../views/user/userNickname.vue";
import userPhone from "../views/user/userPhone.vue";
import posting from "../views/user/posting.vue";
import life from "../views/life/life.vue";
import postingDetail from "../views/user/postingDetail.vue";
import realname from "../views/my/realname.vue";
import coupon from "../views/user/coupon.vue";
import couponDetail from "../views/user/couponDetail.vue";
import about from "../views/user/about.vue";
import money from '../views/my/money.vue'
import contract from "../views/my/contract.vue"
import collect from '../views/my/collect.vue'
import publish from '../views/my/publish.vue'
import report from '../views/my/report.vue'
import issue from '../views/my/issue.vue'
import settings from '../views/my/settings.vue'
import test from '../views/my/test.vue'
import reportUser from "../views/user/reportUser.vue";
import couponAdd from "../views/user/couponAdd.vue";
import reportAdd from "../views/index/reportAdd.vue";
import reportOK from "../views/index/reportOK.vue";
import tenancyAgreement from "../views/index/tenancyAgreement.vue";
import Sign from "../views/life/Sign.vue";
import Post from "../views/life/Post.vue";


//  配置路由组
const routes = [
    {
        path: '/register',
        component:register,
        meta: {
            TabbarShow: false,
            loginCheck: false
        }
    },
    {
        path: '/login',
        component: login,
        meta: {
            TabbarShow: false,
            loginCheck: false
        }
    },


    /**
     * 首页路由跳转
     */
    {
        path: '/',
        component: index,
        meta: {
            TabbarShow: true,
            loginCheck: true
        }
    },
    {
        path: '/index',
        component: index,
        meta: {
            TabbarShow: true,
            loginCheck: true
        }
    },
    {
        path: '/city',//地址选择
        component: city,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/contractInfo',//合同详情
        component: contractInfo,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/houseInfo',//房源详情
        component: houseInfo,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/more',//更多房源
        component: more,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/search',//房源搜索
        component: search,
        meta: {
            TabbarShow: true,
            loginCheck: true
        }
    },
    {
        path: '/businessTripRental',//商旅短租
        component: businessTripRental,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/enterpriseDiscounts',//企业优惠
        component: enterpriseDiscounts,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/graduationSeason',//毕业季了
        component: graduationSeason,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/nearbyStores',//附近门店
        component: nearbyStores,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    //轮播
    {
        path: '/ba1',
        component: ba1,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/ba2',
        component: ba2,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/ba3',
        component: ba3,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/ba4',
        component: ba4,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/reportAdd',//举报
        name: 'reportAdd',
        component: reportAdd,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/reportOK',//举报完成
        name: 'reportOK',
        component: reportOK,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/tenancyAgreement',//查看租房合同
        name: 'tenancyAgreement',
        component: tenancyAgreement,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },



    /**
     * 生活
     */
    {
        path: '/life',
        component: life,
        meta: {
            TabbarShow: true,
            loginCheck: true
        }
    },
    {
        path: '/post/:postPageId',
        name: 'post',
        component: Post,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    {
        path: '/sign',
        name: 'sign',
        component: Sign,
        meta: {
            TabbarShow: false,
            loginCheck: true
        }
    },
    /**
     * my
     */
    {
        path: '/my',
        component: my,
        meta: {
            TabbarShow: true
        }
    },
    {
        path: '/activity',
        component: activity,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/message',
        component: message,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/realname',
        component: realname,
        meta: {
            TabbarShow: false
        }
    },
    /**
     * user
     */

    {
        path: '/about',
        component: about,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/userDetail',
        component: userDetail,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/userNickname',
        component: userNickname,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/userPhone',
        component: userPhone,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/posting',
        component: posting,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/postingDetail',
        component: postingDetail,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/coupon',
        component: coupon,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/couponDetail',
        component: couponDetail,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/couponAdd',
        component: couponAdd,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/reportUser',
        component: reportUser,
        meta: {
            TabbarShow: false
        }
    },



    //----------
    {
        path: '/money',
        component: money,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/contract',
        component: contract,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/collect',
        component: collect,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/publish',
        component: publish,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/coupon',
        component: coupon,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/report',
        component: report,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/about',
        component: about,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/settings',
        component: settings,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/test',
        component: test,
        meta: {
            TabbarShow: false
        }
    },
    {
        path: '/issue',
        component: issue,
        meta: {
            TabbarShow: false
        }
    },

]


export function createRouter() {
    const router = _createRouter({
        history: createWebHistory(),
        routes   //绑定路由组 和 路由管理者
    })

    // 配置全局前置守卫
    router.beforeEach((to, from, next) => {
        // 在这里执行你的拦截逻辑
        // 例如，检查用户是否已登录，或者是否有权限访问该页面
        if (to.meta.loginCheck) {//是否需要登录拦截
            if (useStore().$state.token === null || useStore().$state.token === '') {
                console.log(useStore().$state.token);
                next('/login');
            } else {
                next();
            }
        } else {
            next();
        }
    });

    return router
}
